package com.cos.openapi.web.interceptor;

import com.cos.openapi.common.Const;
import com.cos.openapi.entity.AdminUser;
import com.cos.openapi.services.AdminUserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * @author: COS
 * @time: 2021/11/26 11:32
 * @description:
 */
public class UserLogInterceptor implements HandlerInterceptor {
    @Autowired
    private AdminUserServices as;
    long start;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        start = System.currentTimeMillis();
        System.out.println(as);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("日志记录:" + request.getMethod());
//        System.out.println(request.getRequestURL().toString());
//        System.out.println(request.getRequestURI().toString());
        System.out.println("日志记录:" + handler.toString());
        System.out.println("日志记录:" + request.getParameter("email"));
        System.out.println("日志记录:" + request.getParameterMap().entrySet().toString());
        System.out.println("日志记录:" + request.getRemoteAddr().toString());
//        System.out.println(((AdminUser) request.getSession().getAttribute(Const.IS_LOGIN)).getId());
        System.out.println("日志记录:" + new Date());
        long end = System.currentTimeMillis();
        System.out.println("日志记录:执行时间=>" + (end - start));
    }

}
